/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.EditorMenu;

import GUI.Dialogs.GridOptionsDialog;
import General.CurrentData;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author David
 */
public class ViewMenu extends JMenu
{

    private JCheckBoxMenuItem showAssetBrowserItem = new JCheckBoxMenuItem("Asset Browser");
    private JCheckBoxMenuItem fullscreenItem = new JCheckBoxMenuItem("Fullscreen");
    private JMenuItem gridOptionsItem = new JMenuItem("Grid Options");
    private JMenuItem addCameraItem = new JMenuItem("Add Camera");

    public ViewMenu()
    {
        setEnabled(false);
        fullscreenItem.setSelected(CurrentData.getConfiguration().getSettings().get("fullscreen").equals("true"));
        showAssetBrowserItem.setSelected(CurrentData.getConfiguration().getSettings().get("assetbrowsershown").equals("true"));
        setText("View");
        add(showAssetBrowserItem);
        add(fullscreenItem);
        add(gridOptionsItem);
        add(addCameraItem);
        initActions();
    }

    private void initActions()
    {
        addCameraItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                CurrentData.getEditorWindow().getB3DApplication().createCam();
            }
        });
        gridOptionsItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                new GridOptionsDialog();
            }
        });
        fullscreenItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                if (fullscreenItem.isSelected())
                {
                    CurrentData.getEditorWindow().dispose();
                    CurrentData.getEditorWindow().setUndecorated(true);
                    CurrentData.getEditorWindow().setSize(Toolkit.getDefaultToolkit().getScreenSize());
                    CurrentData.getEditorWindow().setLocation(0, 0);
                    CurrentData.getEditorWindow().setVisible(true);
                } else
                {
                    CurrentData.getEditorWindow().dispose();
                    CurrentData.getEditorWindow().setUndecorated(false);
                    CurrentData.getEditorWindow().setSize(1360, 768);
                    CurrentData.getEditorWindow().setLocationRelativeTo(null);
                    CurrentData.getEditorWindow().setVisible(true);
                }
                CurrentData.getConfiguration().getSettings().put("fullscreen", Boolean.toString(fullscreenItem.isSelected()));
                CurrentData.getConfiguration().save();
                CurrentData.getEditorWindow().arrangeComponentSizes();
            }
        });
        showAssetBrowserItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                CurrentData.getAssetBrowserDialog().setVisible(showAssetBrowserItem.isSelected());
                CurrentData.getConfiguration().getSettings().put("assetbrowsershown", "" + showAssetBrowserItem.isSelected());
                CurrentData.getConfiguration().save();
            }
        });
    }

    /**
     *
     * @return
     */
    public JCheckBoxMenuItem getShowAssetBrowserItem()
    {
        return showAssetBrowserItem;
    }
}
